{% extends 'CHOMPSGIBundle:Workflow:base.html.twig' %}
{% block subtitle %} Listar {% endblock %} 

{% block content %} 


    		<div style="padding: 20px 0;">
			{% spaceless %}
					{% if 'EDITAR_WORKFLOW' in permisos %}
						<a class="btn" href="{{ path("workflow_nuevo") }}">Crear workflow</a>
						<a class="btn btn-danger btnBorrar" > Eliminar </a>
					{% endif %}
			{% endspaceless %}				
			</div>

            <table class="table table-condensed listado">
            		
            		<!-- Cabeceras de la tabla-->
                    <tr>
                		<th>&nbsp;</th>
						<th>Nombre</th>
						<th>Empresa</th>
                        <th>Desde</th>
						<th>Hasta</th>
		            </tr>

                    <!-- Workflows -->
                    {% for workflow in workflows %}
						{% if workflow.borrado == 0 %}						
							
						<tr>
							<td> <input type="checkbox" id="{{workflow.id}}" name="{{workflow.id}}"/></td> 
							<td> <a href="{{ path('workflow_ver',{ 'id': workflow.id } ) }}">	{{workflow.nombre | default("") }} </a></td>
							<td> {{workflow.empresa}}</td>
							<td> {{workflow.desde}}</td>
							<td> {{workflow.hasta}}</td>
						</tr>
							
						{% endif %}
                    {% endfor %}

                    <tr> 
                    	<td colspan="5"> 
                    		{{ pagerfanta (workflows, 'twitter_bootstrap_translated' , { 'prev_message' : 'Anterior', 'next_message': 'Siguiente'} ) }}  <!-- ,  -->
                    	</td> 
                    </tr>
            </table>
			

			<!-- Mensaje de confirmaçión de borrado -->
			<div class="modal fade" id="confirmMsg" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
				<div class="modal-dialog">
				  <div class="modal-content">
				    <div class="modal-header">
				      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
				      <h4 class="modal-title">&iquest;Eliminar Workflow?</h4>
				    </div>
				    <div class="modal-body">
				      &iquest;Est&aacute; seguro que desea eliminar el/los elementos seleccionados?
				    </div>
				    <div class="modal-footer">
				      <a class="btn " href="#" data-dismiss="modal">Cancelar</a>
				      <a class="btn btn-default btn-danger" href="#" onClick="borrarGrupos();"> Eliminar </a>
				    </div>
				  </div>
				</div>
			</div>
   

   	<script>

   		var checkedWorkflows = '';

		//Mostrar mensaje de confirmacion		
		$('.btnBorrar').click( function(){
			if($("input:checked").length > 0)
				$('#confirmMsg').modal('show');
			else
				alert('Debe seleccionar al menos un workflow');
		});  
		
		//Obtener checkboxes tildados
		$('#confirmMsg').on('show.bs.modal', function () {
			$("input:checked").each(function() {
				var empchecked = '';
				empchecked = $(this).attr('id') ;
				checkedWorkflows += empchecked +',';
			});
			if (checkedWorkflows != '')
				checkedWorkflows = checkedWorkflows.slice(0, checkedWorkflows.length-1);
		});

		//inicializar checkboxes tildados
		$('#confirmMsg').on('hide.bs.modal', function () {
			checkedWorkflows = '';
		});

		//Borrar workflows tildadas
		function borrarGrupos(){
			URLBorrarWorkflows = '';
			URLBorrarWorkflows = "{{ path('workflow_borrar',{ 'id': 0} ) }}";
			URLBorrarWorkflows = URLBorrarWorkflows.slice(0, URLBorrarWorkflows.length-1);
			URLBorrarWorkflows+= checkedWorkflows; 
			window.location = URLBorrarWorkflows;
		}

    </script>

{% endblock %}
